package system.task.tasks;

import framework.utils.JsonUtil;
import lombok.SneakyThrows;
import org.springframework.stereotype.Component;
import system.task.ExecutorContext;
import system.task.Task;
import system.task.TaskExecutor;
import system.task.TaskLogger;

@Component
public class TestPrintTask implements TaskExecutor {

    @SneakyThrows
    @Override
    public void run(ExecutorContext context) {
        TaskLogger logger = context.getLogger();
        Task task = context.getTask();
        logger.writeln("*** BEGIN: " + task.getName());
        logger.writeln(JsonUtil.toJsonString(task, true));
        logger.writeln("*** PARAM ***");
        context.getParam().forEach((k, v) -> {
            context.getLogger().writeln("%s: %s", String.valueOf(k), String.valueOf(v));
        });
        logger.writeln("*** END: " + task.getName());
    }
}
